package com.mobimap.nhom9.gui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;

public abstract class AbstractActivity extends Activity {
	public static final int GET_CODE = 0;
	private EditText txtKeyword;
	private ImageButton btnSearch;
	private ImageView imgHome;
	public static int id;
	public static String place_type;
	public static Boolean isMark = false;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		setContentView(this.getLayout());
		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title_search);
		
		//Init control
		this.txtKeyword = (EditText) this.findViewById(R.id.edittextKeyword);
		this.btnSearch = (ImageButton) this.findViewById(R.id.imageButtonSearch);
		this.imgHome = (ImageView) this.findViewById(R.id.imageHome);
		this.onSearchAction();
		
		//Call process from implement class
		this.onProcess(savedInstanceState);
	}	
	


	/**
	 *@region - Helper method for GUI process
	 */
	private void onSearchAction() {
		// TODO Auto-generated method stub
		this.btnSearch.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				String keywork = txtKeyword.getText().toString();
				
				Bundle bundle = new Bundle();
				bundle.putString("search_type", "dia_diem");
				bundle.putString("keywork", keywork);
				
				Intent intent = new Intent(getApplicationContext(), PlaceResultActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				intent.putExtras(bundle);
				Log.e("GUI","i = "+intent.toString());
				startActivity(intent);
			}
		});
		this.imgHome.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getBaseContext(), MainActivity.class);
				startActivity(intent);
			}
		});
	}
	protected void setKeyword(String keyword)	{
		this.txtKeyword.setText(keyword);
	}
	/**
	 * @region Abstract method for activity - onProcess will replace onCreate in child class
	 */
	protected abstract void onProcess(Bundle savedInstanceState);
	protected abstract int getLayout();
	
}
